﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package reprise.tweens {
    import flash.events.*;
    import reprise.commands.*;
    import reprise.events.*;
    import flash.display.*;
    import flash.utils.*;

    public class SimpleTween extends AbstractAsynchronousCommand {

        protected var m_preventFrameDropping:Boolean;
        protected var m_isPaused:Boolean;// = false
        protected var m_lastFrameTime:int;
        protected var m_currentTime:int;
        protected var m_duration:int;
        protected var m_direction:int;
        protected var m_delay:int;
        protected var m_tweenedProperties:Array;
        protected var m_timeAdjust:int;
        protected var m_frameDuration:int;
        protected var m_startTime:int;

        public static const DIRECTION_BACKWARD:int = -1;
        public static const DIRECTION_FORWARD:int = 1;
        protected static const g_frameEventDispatcher:Shape = new Shape();

        public function SimpleTween(_arg1:int=1, _arg2:uint=0, _arg3:uint=0){
            m_duration = _arg1;
            if ((((m_duration <= 0)) || (isNaN(m_duration)))){
                m_duration = 1;
            };
            m_delay = _arg2;
            if (_arg3 != 0){
                m_preventFrameDropping = true;
                m_frameDuration = (1000 / _arg3);
            };
            m_currentTime = 0;
            m_direction = DIRECTION_FORWARD;
            m_tweenedProperties = [];
        }
        public function setIsPaused(_arg1:Boolean):void{
            if (((!(m_isExecuting)) && (_arg1))){
                return;
            };
            if (_arg1){
                g_frameEventDispatcher.removeEventListener(Event.ENTER_FRAME, executeTick);
                m_isExecuting = false;
            } else {
                m_startTime = (((getTimer() - m_currentTime) - m_delay) - m_timeAdjust);
                g_frameEventDispatcher.addEventListener(Event.ENTER_FRAME, executeTick);
                m_isExecuting = true;
            };
            m_isPaused = _arg1;
        }
        public function stopTween():void{
            m_isPaused = false;
            g_frameEventDispatcher.removeEventListener(Event.ENTER_FRAME, executeTick);
            m_isExecuting = false;
        }
        public function getDuration():int{
            return (m_duration);
        }
        public function finish():void{
            if (!m_isExecuting){
                return;
            };
            stopTween();
            m_currentTime = m_duration;
            tweenProperties();
            dispatchEvent(new TweenEvent(Event.COMPLETE, true));
        }
        public function setDuration(_arg1:int):void{
            m_currentTime = ((m_currentTime / m_duration) * _arg1);
            m_duration = _arg1;
        }
        public function startTween(_arg1:Boolean=false):void{
            m_isPaused = false;
            m_isCancelled = false;
            if (((!(m_isExecuting)) && ((m_currentTime < m_duration)))){
                g_frameEventDispatcher.addEventListener(Event.ENTER_FRAME, executeTick);
                m_isExecuting = true;
                m_startTime = (m_lastFrameTime = (getTimer() + m_currentTime));
                m_timeAdjust = 0;
                dispatchEvent(new TweenEvent(TweenEvent.START, true));
                if (_arg1){
                    executeTick();
                };
            };
        }
        protected function executeTick(_arg1:Event=null):void{
            var _local2:int = getTimer();
            if (m_preventFrameDropping){
                if ((_local2 - m_lastFrameTime) > m_frameDuration){
                    m_timeAdjust = (m_timeAdjust + ((_local2 - m_lastFrameTime) - m_frameDuration));
                };
                m_lastFrameTime = _local2;
            };
            m_currentTime = (((_local2 - m_startTime) - m_timeAdjust) - m_delay);
            if (m_currentTime < 0){
                return;
            };
            if (m_currentTime > m_duration){
                m_currentTime = m_duration;
            };
            tweenProperties();
            dispatchEvent(new TweenEvent(TweenEvent.TICK, true));
            if (m_currentTime == m_duration){
                stopTween();
                dispatchEvent(new TweenEvent(Event.COMPLETE, true));
            };
        }
        public function isRunning():Boolean{
            return (m_isExecuting);
        }
        public function addTweenPropertyVO(_arg1:TweenedPropertyVO):void{
            m_tweenedProperties.push(_arg1);
        }
        public function removeTweenProperty(_arg1:TweenedPropertyVO):void{
            var _local2:int;
            while (_local2 < m_tweenedProperties.length) {
                if (TweenedPropertyVO(m_tweenedProperties[_local2]) == _arg1){
                    m_tweenedProperties.splice(_local2, 1);
                    return;
                };
                _local2++;
            };
        }
        public function setDirection(_arg1:int):void{
            m_direction = _arg1;
        }
        public function addTweenProperty(_arg1:Object, _arg2:String, _arg3:Number, _arg4:Number, _arg5:Function=null, _arg6:Boolean=false, _arg7:Boolean=false, _arg8:Array=null):void{
            var _local9:TweenedPropertyVO;
            if ((_arg1 is TweenedPropertyVO)){
                m_tweenedProperties.push(_arg1);
            } else {
                _local9 = new TweenedPropertyVO(_arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8);
                m_tweenedProperties.push(_local9);
            };
        }
        public function getTime():int{
            return (m_currentTime);
        }
        public function getDirection():int{
            return (m_direction);
        }
        override public function didSucceed():Boolean{
            return (true);
        }
        override public function reset():void{
            super.reset();
            resetTween();
        }
        public function resetTween():void{
            stopTween();
            m_currentTime = 0;
        }
        public function setTime(_arg1:int):void{
            m_currentTime = _arg1;
        }
        public function addMultipleProperties(_arg1:Object, _arg2:Array, _arg3:Array, _arg4:Array, _arg5:Function=null, _arg6:Boolean=false, _arg7:Array=null):void{
            var _local9:String;
            var _local10:Number;
            var _local11:Number;
            var _local12:Boolean;
            var _local13:TweenedPropertyVO;
            var _local8:int;
            while (_local8 < _arg2.length) {
                _local9 = _arg2[_local8];
                _local10 = _arg3[_local8];
                _local11 = _arg4[_local8];
                _local12 = (_arg1[_local9] is Function);
                _local13 = new TweenedPropertyVO(_arg1, _local9, _local10, _local11, _arg5, _arg6, _local12, _arg7);
                m_tweenedProperties.push(_local13);
                _local8++;
            };
        }
        public function reverse():void{
            m_currentTime = (m_duration - m_currentTime);
            m_direction = ((m_direction == DIRECTION_FORWARD)) ? DIRECTION_BACKWARD : DIRECTION_FORWARD;
            var _local1:int;
            while (_local1 < m_tweenedProperties.length) {
                TweenedPropertyVO(m_tweenedProperties[_local1]).reverse();
                _local1++;
            };
        }
        override public function toString():String{
            return ("reprise.tweens.SimpleTween");
        }
        override public function execute(... _args):void{
            if (m_isExecuting){
                return;
            };
            m_isCancelled = false;
            startTween(true);
        }
        public function isPaused():Boolean{
            return (m_isPaused);
        }
        override public function cancel():void{
            resetTween();
            super.cancel();
        }
        protected function tweenProperties():void{
            var _local1:TweenedPropertyVO;
            var _local2:int;
            while (_local2 < m_tweenedProperties.length) {
                _local1 = TweenedPropertyVO(m_tweenedProperties[_local2]);
                _local1.tweenProperty(m_duration, m_currentTime);
                _local2++;
            };
        }

    }
}//package reprise.tweens 
